from DNNTrainer import DNNTrainer
from TrainData import TrainData

   #%%%% 
## 路径
fileName = "骨架参数20220619.csv"

## 数据起始列号
startIndex = 1
## 输入数据列数
inNum = 3
## 输入与输出间隔列数
outSpaceIndex = 0
## 输出数据列数
outNum = 4
## 早停训练次数
earlyStopEpoch = 20

## 获得训练数据
dataObj = TrainData(fileName)
## 设定读取参数
dataObj.SetReadFileParams(startIndex, inNum, outSpaceIndex, outNum)

#%%%% 
## 路径
fileName = "滞回参数20220612.csv"

## 数据起始列号
startIndex = 1
## 输入数据列数
inNum = 4
## 输入与输出间隔列数
outSpaceIndex = 0
## 输出数据列数
outNum = 4
## 早停训练次数
earlyStopEpoch = 80

## 获得训练数据
dataObj = TrainData(fileName)
## 设定读取参数
dataObj.SetReadFileParams(startIndex, inNum, outSpaceIndex, outNum)

#%%%%           
trainFileName = "骨架参数--训练集20220622.csv"
testFileName = "骨架参数--验证集20220622.csv"

## 数据起始列号
startIndex = 1
## 输入数据列数
inNum = 3
## 输入与输出间隔列数
outSpaceIndex = 0
## 输出数据列数
outNum = 4
## 早停训练次数
earlyStopEpoch = 20

## 获得训练数据
dataObj = TrainData(trainFileName)
## 获得测试数据
dataObj.SetTestFilePath(testFileName)
## 设定读取参数
dataObj.SetReadFileParams(startIndex, inNum, outSpaceIndex, outNum)

#%%%%           
trainFileName = "滞回参数--训练集20220622.csv"
testFileName = "滞回参数--验证集20220622.csv"

## 数据起始列号
startIndex = 1
## 输入数据列数
inNum = 4
## 输入与输出间隔列数
outSpaceIndex = 0
## 输出数据列数
outNum = 4
## 早停训练次数
earlyStopEpoch = 50

## 获得训练数据
dataObj = TrainData(trainFileName)
## 获得测试数据
dataObj.SetTestFilePath(testFileName)
## 设定读取参数
dataObj.SetReadFileParams(startIndex, inNum, outSpaceIndex, outNum)

   #%%%%
   
## 构造求解器
trainer = DNNTrainer(dataObj, 24, 2, 'relu', 'Adam')
trainer.SetEarlyStop(earlyStopEpoch, 'mse')
trainer.Train(1000)
trainer.PlotLoss()

#%%%%  

## 绘制结果散点图
trainer.PlotPredictions(False)

#%%%%  

## 文件夹相对全路径
relativeDirectPath = '.\\test'
## 保存结果
trainer.SaveModel(relativeDirectPath)

#%%%% 

## 初始化保存路径
directPath = '.\\TenTestAdamRelu2-12\\Skeleton'
activations = 'relu'

#%%%% 

## 初始化保存路径
directPath = '.\\TenTestAdamRelu2-12\\Hysteretic'
activations = 'relu'

#%%%% 

test = [ 'relu', 'elu' ]

for obj in test:
    print(obj)



#%%%% 

## 初始化保存路径
directPath = '.\\HyperParameter\\selu\\Optimizer'
## 激活函数
activations = 'selu'
## 优化器
optimizer = 'Adam'
## 神经网络层数
layerCount = 2
## 隐藏层神经元数目
neuronCount = 24
## 文件名
dotMFileName = 'AUDMColumnH'

def mutliTrain(tdirectPath, tneuronCount, tlayerCount, tactivations, toptimizer):
    ## 生成10次
    for i in range(0, 10):
        ## 更新模型名称
        newdotMFileName = dotMFileName + str(i)
        ## 文件夹名称
        subDirectPath = tdirectPath + '\\' + str(i)
        ## 构造求解器
        trainer = DNNTrainer(dataObj, tneuronCount, tlayerCount, tactivations, toptimizer)
        trainer.SetEarlyStop(earlyStopEpoch, 'mse')
        trainer.Train(1000, 0)
        ## 保存结果
        trainer.SaveModel(subDirectPath, newdotMFileName)

#%%%% 
optimizerList = ['Adadelta', 'Adagrad', 'Adam', 'Adamax', 'Nadam', 'RMSprop', 'SGD']

for toptimizer in optimizerList:
    ## 更新路径
    tdirectPath = directPath + '\\' + toptimizer
    ## 数据训练
    mutliTrain(tdirectPath, neuronCount, layerCount, activations, toptimizer)

#%%%% 






    
